home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
- <stack>
- <name>in</name>
- <id>-1</id>
- <cardCount>16</cardCount>
- <cardID>3026</cardID>
- <listID>4203</listID>
- <cantModify><false /></cantModify>
- <cantDelete><false /></cantDelete>
- <cantAbort><false /></cantAbort>
- <cardSize>
- <width>512</width>
- <height>342</height>
- </cardSize>
- <script>-- Allow Instance Variables for buttons, fields, cards, and backgrounds.
- -- (c) 1991, 1992 copyright Apple Computer, all rights reserved.
- -- Version 1.0 for HyperCard 2.1
-
- -- This belongs in the stack script of your stack.
- -- (Just putting it in the Home script is not the best. If you give
- -- your stack to someone, instance variables will stop working.)
-
- -- You call these: putVar, getVar, allowInstVars
- -- Bonus handlers: removeVar, hasThisVar, allVarsOf
- -- Internal use only: instVar, createBkgndFld, ss, hh
-
- on putVar cdBk,myID,variable,value,cardID
- -- Store the value of this variable in this object
- -- Example: putVar cd,the id of me,fred,45
- -- a missing cardID means on the current card
- -- cdBk is cd or bk
- -- (where is this object? cd is card, bk is background)
- -- myID is: the short id of me
- -- variable is the name under which you want to store this value
- -- value is what you want to store
- -- value may not contain { or } characters
- -- cardID (optional) the id of the card that contains the object
-
- put instVar(cdBk,myID,variable,value,cardID) into dummy
- end putVar
-
-
- function getVar cdBk,myID,variable,cardID
- -- Retrieve the value of this variable in this object
- -- Example: getVar cd,the id of me,fred
- -- a missing cardID means on the current card
- -- cdBk is cd or bk
- -- (where is this object? cd is card, bk is background)
- -- myID is: the short id of me
- -- variable is the name under which you want to store this value.
- -- variable may not contain { or } characters
- -- it may contain spaces or other characters
- -- cardID (optional) the id of the card that contains the object
-
- return instVar(cdBk,myID,variable,"{}",cardID) --retrieval
- end getVar
-
-
- function instVar cdBk,myID,variable,value,cardID
- -- Get or put the value of a variable that belongs to a
- -- card button, card field, the card itself, a bkgnd button,
- -- shared field, or the bkgnd itself.
-
- -- User should not call this. Called from getVar, putVar and removeVar.
-
- -- Instance variables for bkgnd fields are not supported! This is
- -- because it a background field is part shared and part local to
- -- the card. Attach the variable to the card or to a shared
- -- field instead.
-
- -- Works for both storing and retireving, for both objects on a
- -- card and object shared across a background.
-
- -- If value is "{}" then we are retrieving a value from the
- -- dictionary.
-
- -- Note that myID is not enough information to actually find the
- -- button or field (we don't know which it is). But we don't
- -- care. We don't have to get at the button or field itself,
- -- just find it's variables in the dictionary!
-
- -- The search keys
- put "{" & variable & "{" & myID & "{" into startKey --{Fred{21{
- put "}" & variable & "}" & myID & "}" into endKey --}Fred}21}
-
- if cardID is empty
- then put the short id of this card into holder -- on current card
- else put cardID into holder --on a specific card
-
- if cdBk = "bk"
- then put "call allowInstVars first" into theFld --background objects
- else put "you must call allowInstVars" into theFld --card specific
- -- The names of these fields are funny so that the user will know
- -- what to do when he gets and error because the fields are not there.
-
- -- If the field is missing, you must call allowInstVars (just once in
- -- each background) to initialize some hidden fields.
- put offset(startKey,bkgnd fld theFld of cd id holder) ¬
- into startLoc --loc of {Fred{21{
-
- if startLoc is 0 then
- --the key wasn't found
- if (cdBk is not "cd") and (cdBk is not "bk")
- then answer "First arg of putVar must be bk or cd" with "OK"
-
- if value = "{}" then --getting and it was not found
- put cdBK && "id" && myID && variable && "on card" && holder
- answer "You must putVar into a variable" & return &¬
- "before using getVar to read it."
- return "no value in:" && variable
- else
- --putting a value, create a new variable
- put return & startKey & value & endKey after bkgnd fld ¬
- theFld of cd id holder
- return value
- end if
- end if
-
- put offset(endKey,bkgnd fld theFld of cd id holder) ¬
- into endLoc --loc of }Fred}21}
-
- add length(startKey) to startLoc --loc after key, start of value
- subtract 1 from endLoc
- if value = "{}" then --getting a value
- -- Retrieve the value of the variable
- return char startLoc to endLoc of bkgnd fld theFld of cd id holder
- else
- if value = "re{}move" then
- --remove the variable to save space
- subtract length(startKey) from startLoc --loc before key
- add length(startKey) to endLoc --loc after end key
- put empty into char startLoc to endLoc of bkgnd fld ¬
- theFld of cd id holder -- remove keys and value
- else
- -- Store the value in the dictionary over old value
- put value into char startLoc to endLoc of bkgnd fld ¬
- theFld of cd id holder
- end if
- return value
- end if
- end instVar
-
- on allowInstVars
- -- Create a field for the instance variable dictionary.
- -- It has a funny name so the user will know what to do
- -- when he gets and error because the field is not there.
- createBkgndFld "you must call allowInstVars" --card variables
- createBkgndFld "call allowInstVars first" --bkgnd variables
- set sharedText of bkgnd fld "call allowInstVars first" to true
- set loc of bkgnd fld "call allowInstVars first" to 160,250
- end allowInstVars
-
- on createBkgndFld theName
- -- Create hidden background field if not there already.
- -- Use this field for storing the dictionary of names and values.
- repeat with ii = 1 to the number of bkgnd fields
- put the short name of bkgnd field ii into myName
- if myName is theName
- then
- put "already there!"
- exit createBkgndFld --already exists
- end if
- end repeat
-
- -- Create a background field for the instance variable dictionary.
- doMenu "background"
- doMenu "New Field"
- put the number of bkgnd fields into num
- set the name of field num to theName
- hide field theName -- important!
- choose browse tool
- doMenu "Background" --get out of Background mode
- put "new is " & num --debugging
- end createBkgndFld
-
- on removeVar cdBk,myID,variable,cardID
- -- Remove this variable in this object
- -- Is not necessary. Only do it to save space when destroying
- -- a button or other object.
- -- Example: removeVar cd,the id of me,fred
- -- a missing cardID means on the current card
- -- see getVar for the meaning of the arguments
-
- put instVar(cdBk,myID,variable,"re{}move",cardID) into data
- -- this specal value means remove the variable from the dictionary
- end removeVar
-
- -- Bonus handlers: removeVar, hasThisVar, allVarsOf
-
- function hasThisVar cdBk,myID,variable,cardID
- -- Return true if this object has a variable of this name
- -- So a script can ask if the object has one before trying to read it.
- -- Example: hasThisVar(cd,the id of me,"fred")
- -- a missing cardID means on the current card
- -- cdBk is cd or bk
- -- (where is this object? cd is card, bk is background)
- -- myID is: the short id of me
- -- variable is the name under which you want to store this value
- -- cardID (optional) the id of the card that contains the object
-
- put "{" & variable & "{" & myID & "{" into startKey --{Fred{21{
-
- if cardID is empty
- then put the short id of this card into holder -- on current card
- else put cardID into holder --on a specific card
-
- if cdBk = "bk"
- then put "call allowInstVars first" into theFld --background objects
- else put "you must call allowInstVars" into theFld --card specific
-
- return offset(startKey,bkgnd fld theFld of cd id holder) is not 0
- end hasThisVar
-
- function allVarsOf cdBk,myID,cardID
- -- Return a list of the names of the variables in this object now.
- -- Returns a list of items separated by commas
- -- Example: allVarsOf(cd,the id of me)
- -- a missing cardID means on the current card
- -- cdBk is cd or bk
- -- (where is this object? cd is card, bk is background)
- -- myID is: the short id of me
- -- cardID (optional) the id of the card that contains the object
-
- put "{" & myID & "{" into startKey --{21{
-
- if cardID is empty
- then put the short id of this card into holder -- on current card
- else put cardID into holder --on a specific card
-
- if cdBk = "bk"
- then put "call allowInstVars first" into theFld --background objects
- else put "you must call allowInstVars" into theFld --card specific
-
- put bkgnd fld theFld of cd id holder into rawData
- put empty into list
- repeat
- put offset(startKey,rawData) into index --{21{
- if index = 0 then return list
- put index-1 into ii
- repeat until ii = 1 -- will not leave this way
- if char ii of rawData = "{" then
- if list is not empty then put "," after list
- put (char ii+1 to index-1 of rawData) after list --fred
- delete char 1 to index+5 of rawData -- remove start of this
- -- variable so the next one will be the first one found
- else
- subtract 1 from ii --backup one char
- end if
- end repeat
- end repeat
- end allVarsOf
-
- on ss
- -- For debugging only! Show the raw data
- show bkgnd fld "you must call allowInstVars"
- show bkgnd fld "call allowInstVars first"
- end ss
-
- on hh
- -- For debugging only! Hide the raw data
- hide bkgnd fld "you must call allowInstVars"
- hide bkgnd fld "call allowInstVars first"
- end hh
- </script>
- <background id="2801" file="background_2801.xml" name="" />
- <card id="3026" file="card_3026.xml" marked="false" name="" owner="2801" />
- <card id="6946" file="card_6946.xml" marked="false" name="" owner="2801" />
- <card id="7375" file="card_7375.xml" marked="false" name="" owner="2801" />
- <card id="7669" file="card_7669.xml" marked="false" name="" owner="2801" />
- <card id="9254" file="card_9254.xml" marked="false" name="" owner="2801" />
- <card id="7689" file="card_7689.xml" marked="false" name="" owner="2801" />
- <card id="7940" file="card_7940.xml" marked="false" name="" owner="2801" />
- <card id="3791" file="card_3791.xml" marked="false" name="" owner="2801" />
- <card id="6694" file="card_6694.xml" marked="false" name="" owner="2801" />
- <card id="9024" file="card_9024.xml" marked="false" name="" owner="2801" />
- <card id="3928" file="card_3928.xml" marked="false" name="" owner="2801" />
- <card id="8322" file="card_8322.xml" marked="false" name="" owner="2801" />
- <card id="4497" file="card_4497.xml" marked="false" name="" owner="2801" />
- <card id="5416" file="card_5416.xml" marked="false" name="" owner="2801" />
- <card id="8462" file="card_8462.xml" marked="false" name="" owner="2801" />
- <card id="4916" file="card_4916.xml" marked="false" name="" owner="2801" />
- </stack>
-